package com.janyee.buddha

import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.janyee.buddha.adapter.BookFliperAdapter
import com.janyee.buddha.adapter.TestAdapter
import com.janyee.buddha.listener.BookEventListener
import com.janyee.buddha.view.BookFliper
import com.janyee.buddha.view.TextPainter
import java.nio.charset.Charset

class MainActivity : AppCompatActivity(), BookEventListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(LayoutInflater.from(applicationContext).inflate(R.layout.book_content,null,false))
        setContentView(R.layout.activity_main)
        var builder = StringBuilder()
        var ins = assets.open("T30n1564.txt")
        var b = ByteArray(ins.available())
        var c = ins.read(b)
        builder.append(String(b, Charset.forName("GBK")).replace(" ", "").replace("\r\n\r\n", "\r\n").replace("\t", ""))
        Log.e("++", "read ok!")
        ins.close()
        b = ByteArray(0)
        var fliper = findViewById<BookFliper>(R.id.fliper)
        fliper.setAdapter(BookFliperAdapter(applicationContext, builder, 28f, 0f, 0, TextPainter(60f, Color.BLACK, Color.WHITE, Color.GRAY)))
//        fliper.setAdapter(TestAdapter())
    }

    override fun OnChoosedText() {
        Log.e("====", "choose text")
    }


}
